using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MonoTouch.Foundation;
using MonoTouch.UIKit;
using CoachingOrganizer.iOS.Controllers;
using CoachingOrganizer.Logic.Models.Common;

namespace CoachingOrganizer.iOS.DataSources
{
	public class ChooseToolDataSource : UIPickerViewDelegate, IUIPickerViewDataSource 
    {
        private readonly UIPickerView _view;
        private readonly SupplyGoalDetailsViewController _controller;
        private readonly GoalModel _model;
        private string[] _toolNames;

		public ChooseToolDataSource(UIPickerView view, SupplyGoalDetailsViewController controller, GoalModel model)
        {
            _view = view;
            _controller = controller;
            _model = model;
            _toolNames = GetToolNames().ToArray();
        }

//        public override int GetRowsInComponent(UIPickerView picker, int component)
//        {
//            return _toolNames.Length;
//        }

//        public override string GetTitle(UIPickerView picker, int row, int component)
//        {
//            return _toolNames[row];
//        }
		public override string GetTitle (UIPickerView pickerView, int row, int component)
		{
			return _toolNames[row];
		}

		public int GetComponentCount (UIPickerView pickerView)
		{
			return 1;
		}

		public int GetRowsInComponent (UIPickerView pickerView, int component)
		{
			return _toolNames.Length;
		}

        private IEnumerable<string> GetToolNames()
        {
            string plistFilePath = NSBundle.MainBundle.PathForResource("ToolNames", "plist");
            using (NSArray dataArray = NSArray.FromFile(plistFilePath))
				return NSArray.FromArray<NSString>(dataArray).Cast<NSString>().Select<NSString, string>(s=>s);
        }
    }
}